package com.rwhansen.humidor;

import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class CigarDetailRatingPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private JPanel contentPane;
	private static JTextField textName;
	private static JTextField textGauge;
	private static JTextField textLength;
	private static JTextField textPrice;
	private static JTextField textDateAddedToHumidor;
	private static JTextField textDateSmoked;
	private static JTextField textMadeBy;
	private static JTextField textSize;
	private static JTextField textBody;
	private static JTextField textCARating;
	private static JTextField textCARatingYear;
	private static JTextField textCountry;
	private static JTextField textPurchaseLocation;
	private static JComboBox comboBoxCARatingYear;
	private static JComboBox comboBoxMadeBy;
	private static JComboBox comboBoxSize;
	private static JComboBox comboBoxBody;
	private static JComboBox comboBoxCountry;
	private static JComboBox comboBoxCARating;
	private static JComboBox comboBoxPurchaseLocation;
	private static JTextArea textDescription;
	private static JTextArea textComment;
	private static JSlider ratingSlider;
	private static JButton btnSave;
	private static JButton btnCancel;
	private static JTextField textMinutesSmoked;
	private static JComboBox comboBoxFinished;
	
	private CigarBrandInformation cigarBrandInformation;
	private NumberFormat n;
	private Database ratingsDatabase;
	private boolean delete;
	private static JTextField textFullySmoked;
	
	
	

	
	public CigarDetailRatingPanel(final Cigar cigar, Database ratings) {
		setFont(new Font("GodOfWar", Font.PLAIN, 12));
		setBounds(100, 100, 528, 750);
		//contentPane = new JPanel();
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(null);
		
		getCigarBrandInformation();
		ratingsDatabase = ratings;
		delete = false;
	
//Name
		JLabel lblName = new JLabel("Cigar Name");
		lblName.setBounds(9, 29, 249, 30);
		lblName.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblName);
		
		textName = new JTextField();
		textName.setBounds(269, 29, 249, 30);
		textName.setForeground(Color.BLACK);
		textName.setText(cigar.getName());
		textName.setToolTipText("Cigar Name");
		textName.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		add(textName);
		textName.setColumns(10);
		
//Brand
		JLabel lblBrand = new JLabel("Brand");
		lblBrand.setBounds(9, 59, 249, 30);
		lblBrand.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblBrand);
	
		comboBoxMadeBy = new JComboBox();
		comboBoxMadeBy.setToolTipText("Made By");
		comboBoxMadeBy.setBounds(269, 59, 249, 30);
		comboBoxMadeBy.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxBrands(cigar)));
		comboBoxMadeBy.setForeground(Color.BLACK);
		comboBoxMadeBy.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxMadeBy.setEditable(true);
		add(comboBoxMadeBy);
		
		textMadeBy = new JTextField();
		textMadeBy.setToolTipText("Made By");
		textMadeBy.setText(cigar.getBrand());
		textMadeBy.setForeground(Color.BLACK);
		textMadeBy.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textMadeBy.setColumns(10);
		textMadeBy.setBounds(269, 59, 249, 30);
		textMadeBy.setEditable(false);
		add(textMadeBy);
		
//Size
		JLabel lblSize = new JLabel("Size");
		lblSize.setBounds(9, 89, 249, 30);
		lblSize.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblSize);
		
		comboBoxSize = new JComboBox();
		comboBoxSize.setToolTipText("Size/Shape of Cigar");
		comboBoxSize.setBounds(269, 89, 249, 30);
		comboBoxSize.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxSizes(cigar)));
		comboBoxSize.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxSize.setEditable(true);
		add(comboBoxSize);
		
		textSize = new JTextField();
		textSize.setToolTipText("Size/Shape of Cigar");
		textSize.setText(cigar.getSize());
		textSize.setForeground(Color.BLACK);
		textSize.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textSize.setColumns(10);
		textSize.setBounds(269, 90, 249, 30);
		textSize.setEditable(false);
		add(textSize);
	
//Body
		JLabel lblBody = new JLabel("Body");
		lblBody.setBounds(9, 119, 249, 30);
		lblBody.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblBody);
	
		comboBoxBody = new JComboBox();
		comboBoxBody.setToolTipText("Body");
		comboBoxBody.setBounds(269, 119, 249, 30);
		comboBoxBody.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxBodies(cigar)));
		comboBoxBody.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxBody.setEditable(false);
		add(comboBoxBody);
		
		textBody = new JTextField();
		textBody.setToolTipText("Body");
		textBody.setText(cigar.getBody());
		textBody.setForeground(Color.BLACK);
		textBody.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textBody.setColumns(10);
		textBody.setBounds(269, 119, 249, 30);
		textBody.setEditable(false);
		add(textBody);
		
//Gauge
		JLabel lblGauge = new JLabel("Gauge (must be an inteder)");
		lblGauge.setBounds(9, 149, 249, 30);
		lblGauge.setFont(new Font("GodOfWar", Font.PLAIN, 16));
		add(lblGauge);
		
		textGauge = new JFormattedTextField();
		textGauge.setToolTipText("Cigar Gauge");
		textGauge.setBounds(269, 149, 249, 30);
		textGauge.setText(Integer.toString(cigar.getGauge()));
		textGauge.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		add(textGauge);
		textGauge.setColumns(10);
		
//Length
		JLabel lblLength = new JLabel("Length (must be a number)");
		lblLength.setBounds(9, 179, 249, 30);
		lblLength.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblLength);
		
		textLength = new JFormattedTextField();
		textLength.setToolTipText("Cigar Length");
		textLength.setBounds(269, 179, 249, 30);
		textLength.setText(Double.toString(cigar.getLength()));
		textLength.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		add(textLength);
		textLength.setColumns(10);
		
//Country
		JLabel lblCountry = new JLabel("Country");
		lblCountry.setBounds(9, 209, 249, 30);
		lblCountry.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblCountry);
		
		comboBoxCountry = new JComboBox();
		comboBoxCountry.setToolTipText("Country of Origin");
		comboBoxCountry.setBounds(269, 209, 249, 30);
		comboBoxCountry.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCountries(cigar)));
		comboBoxCountry.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxCountry.setEditable(true);
		add(comboBoxCountry);
		
		textCountry = new JTextField();
		textCountry.setToolTipText("Country of Origin");
		textCountry.setText(cigar.getCountry());
		textCountry.setForeground(Color.BLACK);
		textCountry.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textCountry.setColumns(10);
		textCountry.setBounds(269, 209, 249, 30);
		textCountry.setEditable(false);
		add(textCountry);
		
//CA Rating
		JLabel lblCARating = new JLabel("Cigar Aficionado Rating");
		lblCARating.setBounds(9, 239, 249, 30);
		lblCARating.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblCARating);
		
		comboBoxCARating = new JComboBox();
		comboBoxCARating.setToolTipText("Cigar Aficionado Rating");
		comboBoxCARating.setBounds(269, 239, 249, 30);
		comboBoxCARating.setMaximumRowCount(10);
		comboBoxCARating.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCARatings(cigar)));
		comboBoxCARating.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxCARating.setEditable(false);
		add(comboBoxCARating);
		
		textCARating = new JTextField();
		textCARating.setToolTipText("Cigar Aficionado Rating");
		textCARating.setText(Integer.toString(cigar.getCaRating()));
		textCARating.setForeground(Color.BLACK);
		textCARating.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textCARating.setColumns(10);
		textCARating.setBounds(269, 239, 249, 30);
		textCARating.setEditable(false);
		add(textCARating);
	
//CA Rating Year
		JLabel lblCaRatingYear = new JLabel("CA Rating Year");
		lblCaRatingYear.setBounds(9, 269, 249, 30);
		lblCaRatingYear.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		add(lblCaRatingYear);
		
		comboBoxCARatingYear = new JComboBox();
		comboBoxCARatingYear.setToolTipText("Cigar Aficionado Rating Year");
		comboBoxCARatingYear.setBounds(269, 269, 249, 30);
		comboBoxCARatingYear.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCARatingYears(cigar)));
		comboBoxCARatingYear.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		add(comboBoxCARatingYear);
		

		textCARatingYear = new JTextField();
		textCARatingYear.setToolTipText("Cigar Aficionado Rating Year");
		textCARatingYear.setText(Integer.toString(cigar.getCaRatingYear()));
		textCARatingYear.setForeground(Color.BLACK);
		textCARatingYear.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textCARatingYear.setColumns(10);
		textCARatingYear.setBounds(269, 269, 249, 30);
		textCARatingYear.setEditable(false);
		add(textCARatingYear);
		
//Purchase Location
		JLabel lblPurchaseLocation = new JLabel("Purchase Location");
		lblPurchaseLocation.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblPurchaseLocation.setBounds(9, 299, 249, 30);
		add(lblPurchaseLocation);
		
		comboBoxPurchaseLocation = new JComboBox();
		comboBoxPurchaseLocation.setMaximumRowCount(20);
		comboBoxPurchaseLocation.setEditable(true);
		comboBoxPurchaseLocation.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxPurchaseLocations(cigar)));
		comboBoxPurchaseLocation.setToolTipText("Purchase Location");
		comboBoxPurchaseLocation.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		comboBoxPurchaseLocation.setBounds(269, 299, 249, 30);
		add(comboBoxPurchaseLocation);
		
		textPurchaseLocation = new JTextField();
		textPurchaseLocation.setToolTipText("Purchase Location");
		textPurchaseLocation.setText(cigar.getPurchaseLocation());
		textPurchaseLocation.setForeground(Color.BLACK);
		textPurchaseLocation.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textPurchaseLocation.setColumns(10);
		textPurchaseLocation.setBounds(269, 299, 249, 30);
		textPurchaseLocation.setEditable(false);
		add(textPurchaseLocation);
		
//Price		
		n = NumberFormat.getCurrencyInstance(Locale.US); 
	    
		JLabel lblPrice = new JLabel("Price");
		lblPrice.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblPrice.setBounds(9, 329, 249, 30);
		add(lblPrice);
		
		textPrice = new JFormattedTextField();
		textPrice.setToolTipText("Price of the Cigar");
		textPrice.setText(n.format(cigar.getPrice().doubleValue()));
		textPrice.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textPrice.setColumns(10);
		textPrice.setBounds(269, 329, 249, 30);
		add(textPrice);
		
//Date Added To Humidor
		JLabel lblDateAddedToHumidor = new JLabel("Date Added To Humidor");
		lblDateAddedToHumidor.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblDateAddedToHumidor.setBounds(9, 359, 249, 30);
		add(lblDateAddedToHumidor);
		
		textDateAddedToHumidor = new JFormattedTextField();
		textDateAddedToHumidor.setToolTipText("Date Cigar was added to  Humidor");
		textDateAddedToHumidor.setText(cigar.getDateAddHumidor());
		textDateAddedToHumidor.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textDateAddedToHumidor.setColumns(10);
		textDateAddedToHumidor.setBounds(269, 359, 249, 30);
		add(textDateAddedToHumidor);

//Description
		JLabel lblDescription = new JLabel("Description:");
		lblDescription.setBounds(9, 389, 124, 18);
		add(lblDescription);
		lblDescription.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		
		JScrollPane scrollPaneDescription = new JScrollPane();
		scrollPaneDescription.setBounds(9, 407, 509, 82);
		add(scrollPaneDescription);
		
		textDescription = new JTextArea();
		scrollPaneDescription.setViewportView(textDescription);
		textDescription.setLineWrap(true);
		textDescription.setWrapStyleWord(true);
		textDescription.setToolTipText("Description of Cigar");
		textDescription.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textDescription.setText(cigar.getDescription());
		
//Date Smoked
		JLabel lblDateSmoked = new JLabel("Date Smoked");
		lblDateSmoked.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblDateSmoked.setBounds(9, 489, 249, 30);
		add(lblDateSmoked);
				
		textDateSmoked = new JFormattedTextField();
		textDateSmoked.setToolTipText("Date Cigar Smoked");
		textDateSmoked.setText(cigar.getDateSmoked());
		textDateSmoked.setFont(new Font("GodOfWar", Font.PLAIN, 13));
		textDateSmoked.setColumns(10);
		textDateSmoked.setBounds(269, 489, 249, 30);
		add(textDateSmoked);
				
//My Rating
		JLabel lblMyRating = new JLabel("My Rating");
		lblMyRating.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblMyRating.setBounds(9, 519, 96, 30);
		add(lblMyRating);
		
		ratingSlider = new JSlider();
		ratingSlider.setToolTipText("My Rating of the Cigar");
		ratingSlider.setSnapToTicks(true);
		ratingSlider.setValue(cigar.getMyRating());
		ratingSlider.setPaintLabels(true);
		ratingSlider.setMajorTickSpacing(1);
		ratingSlider.setMaximum(10);
		ratingSlider.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		ratingSlider.setBounds(106, 513, 412, 42);
		add(ratingSlider);
		
//My Comments
		JLabel lblMyComments = new JLabel("My Comments:");
		lblMyComments.setFont(new Font("GodOfWar", Font.PLAIN, 17));
		lblMyComments.setBounds(9, 549, 249, 30);
		add(lblMyComments);
		
		JScrollPane scrollPaneComments = new JScrollPane();
		scrollPaneComments.setBounds(9, 579, 509, 82);
		add(scrollPaneComments);
		
		textComment = new JTextArea();
		textComment.setLineWrap(true);
		scrollPaneComments.setViewportView(textComment);
		textComment.setWrapStyleWord(true);
		textComment.setToolTipText("My Comments");
		textComment.setText(cigar.getComment());
		textComment.setFont(new Font("GodOfWar", Font.PLAIN, 13));

//Was the cigar finished		
		
		comboBoxFinished = new JComboBox();
		comboBoxFinished.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		comboBoxFinished.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxFinished(cigar)));
		comboBoxFinished.setBounds(76, 672, 86, 20);
		add(comboBoxFinished);
		
		textFullySmoked = new JTextField();
		textFullySmoked.setToolTipText("If the cigar was fully smoked");
		textFullySmoked.setText(cigar.getFullySmoked());
		textFullySmoked.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		textFullySmoked.setEditable(false);
		textFullySmoked.setColumns(10);
		textFullySmoked.setBounds(76, 672, 86, 20);
		add(textFullySmoked);
		
		JLabel lblFinished = new JLabel("Finished");
		lblFinished.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		lblFinished.setBounds(19, 675, 64, 14);
		add(lblFinished);
		
//Time Smoked
		JLabel lblTimeToSmoke = new JLabel("Time to smoke (minutes)");
		lblTimeToSmoke.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		lblTimeToSmoke.setBounds(232, 675, 151, 14);
		add(lblTimeToSmoke);
		
		textMinutesSmoked = new JTextField();
		textMinutesSmoked.setText(Integer.toString(cigar.getMinutesSmoked()));
		textMinutesSmoked.setFont(new Font("GodOfWar", Font.PLAIN, 11));
		textMinutesSmoked.setToolTipText("Amount of time it took to smoke the cigar in minutes");
		textMinutesSmoked.setBounds(380, 672, 117, 20);
		add(textMinutesSmoked);
		textMinutesSmoked.setColumns(10);
			
			
//Buttons ---------------------------------------------------------------

//Edit Button
		JButton btnEditCigar = new JButton("Edit Cigar");
		btnEditCigar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				editFields(true);
				delete = true;
			}
		});
		btnEditCigar.setBounds(0, 0, 263, 29);
		add(btnEditCigar);
					
//Remove Cigar Button
		JButton btnRemoveCigar = new JButton("Remove Cigar");
		btnRemoveCigar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				PersonalCigarAssistant.setWindowEnabled(false);
				RemoveCigarFromDatabase remove = new RemoveCigarFromDatabase(cigar, ratingsDatabase.getCigars().indexOf(cigar), Database.RATINGS_DB_FILENAME);
				remove.setVisible(true);
			}
		});
		btnRemoveCigar.setBounds(263, 0, 263, 29);
		add(btnRemoveCigar);
		
//Cancel Button
		btnCancel = new JButton("Cancel");
		btnCancel.setEnabled(true);
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fillDataFields(cigar);
				delete = false;
				editFields(false);
				
				PersonalCigarAssistant.tabbedPane.setSelectedComponent(PersonalCigarAssistant.ratingsScrollPane);
				PersonalCigarAssistant.ratingsTable.changeSelection(0, 0, false, false);
			}
		});
		btnCancel.setBounds(0, 710, 263, 29);
		add(btnCancel);
				
//Save Button
		btnSave = new JButton("Save");
		btnSave.setEnabled(true);
		btnSave.addActionListener(new ActionListener() {
			

			public void actionPerformed(ActionEvent e) {
				BigDecimal newPrice = new BigDecimal(textPrice.getText().replace("$", ""));
				Cigar newCigar = new Cigar(textName.getText());

				newCigar.setBrand(comboBoxMadeBy.getSelectedItem().toString());
				newCigar.setSize(comboBoxSize.getSelectedItem().toString());
				newCigar.setBody(comboBoxBody.getSelectedItem().toString());
				newCigar.setGauge(Integer.parseInt(textGauge.getText()));
				newCigar.setLength(Double.parseDouble(textLength.getText()));
				newCigar.setCountry(comboBoxCountry.getSelectedItem().toString());
				newCigar.setCaRating(Integer.parseInt(comboBoxCARating.getSelectedItem().toString()));
				newCigar.setCaRatingYear(Integer.parseInt(comboBoxCARatingYear.getSelectedItem().toString()));
				newCigar.setDescription(textDescription.getText());				
				newCigar.setPrice(newPrice);
				newCigar.setPurchaseLocation(comboBoxPurchaseLocation.getSelectedItem().toString());
				newCigar.setMyRating(ratingSlider.getValue());
				newCigar.setComment(textComment.getText());
				newCigar.setDateAddHumidor(textDateAddedToHumidor.getText());
				newCigar.setDateSmoked(textDateSmoked.getText());
				newCigar.setQuantity(1);
				newCigar.setModified("T");
				newCigar.setFullySmoked(comboBoxFinished.getSelectedItem().toString());
				newCigar.setMinutesSmoked(Integer.parseInt(textMinutesSmoked.getText()));

//TODO
				newCigar.setRecomend(true);
	
				newCigar.setDayAddHumidor(0);
				newCigar.setMonthAddHumidor(0);
				newCigar.setYearAddHumidor(0);
				
				newCigar.setDaySmoked(0);
				newCigar.setMonthSmoked(0);
				newCigar.setYearSmoked(0);
				if (delete) {
					ratingsDatabase.removeCigarFromDatabase(cigar);
					delete = false;
				}
				ratingsDatabase.addCigarToDatabase(newCigar);
				
			
				Database.writeDatabase(Database.RATINGS_DB_FILENAME, ratingsDatabase);
				PersonalCigarAssistant.refreshTables();
				editFields(false);
				
				PersonalCigarAssistant.tabbedPane.setSelectedComponent(PersonalCigarAssistant.ratingsScrollPane);
//				PersonalCigarAssistant.ratingsTable.changeSelection(0, 0, false, false);
			}
		});
		btnSave.setBounds(263, 710, 263, 29);
		add(btnSave);
		
		
		
		
		
		
		
		editFields(false);
	}
	
	/**
	 * This is what populates all of the combobox drop downs
	 */
	public void getCigarBrandInformation() {
		String cigarBrandInformationFileName = CigarBrandInformation.CBI_FILE_NAME;
		cigarBrandInformation = new CigarBrandInformation();
		File cbiFile = new File(cigarBrandInformationFileName);
		boolean cbiExists = cbiFile.exists();
		if (cbiExists){
			cigarBrandInformation = CigarBrandInformation.readCigarBrandInformation(cigarBrandInformationFileName);
		}
	}
	
	public void fillDataFields(Cigar cigar) {
		textName.setText(cigar.getName());
		comboBoxMadeBy.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxBrands(cigar)));
		comboBoxSize.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxSizes(cigar)));
		comboBoxBody.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxBodies(cigar)));
		textGauge.setText(Integer.toString(cigar.getGauge()));
		textLength.setText(Double.toString(cigar.getLength()));
		comboBoxCountry.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCountries(cigar)));
		comboBoxCARating.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCARatings(cigar)));
		comboBoxCARatingYear.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxCARatingYears(cigar)));
		comboBoxPurchaseLocation.setModel(new DefaultComboBoxModel(cigarBrandInformation.getComboBoxPurchaseLocations(cigar)));
		textPrice.setText(n.format(cigar.getPrice().doubleValue()));
		textDateAddedToHumidor.setText(cigar.getDateAddHumidor());
		textDescription.setText(cigar.getDescription());
		textDateSmoked.setText(cigar.getDateSmoked());
		ratingSlider.setValue(cigar.getMyRating());
		textComment.setText(cigar.getComment());
	}
	
	/**
	 * This will allow the text fields to be edited or no not.
	 * @param edit True - Fields can be edited; False - Fields can not be edited.
	 */
	public static void editFields(boolean edit) {
		boolean initialyVisibleTrue = true;
		boolean initialyVisibleFalse = false;
		if (edit == true) {
			initialyVisibleTrue = false;
			initialyVisibleFalse = true;
		}
		
		textName.setEditable(initialyVisibleFalse);
		comboBoxMadeBy.setVisible(initialyVisibleFalse);
		textMadeBy.setVisible(initialyVisibleTrue);
		comboBoxSize.setVisible(initialyVisibleFalse);
		textSize.setVisible(initialyVisibleTrue);
		comboBoxBody.setVisible(initialyVisibleFalse);
		textBody.setVisible(initialyVisibleTrue);
		comboBoxCountry.setVisible(initialyVisibleFalse);
		textCountry.setVisible(initialyVisibleTrue);
		comboBoxCARating.setVisible(initialyVisibleFalse);
		textCARating.setVisible(initialyVisibleTrue);
		comboBoxCARatingYear.setVisible(initialyVisibleFalse);
		textCARatingYear.setVisible(initialyVisibleTrue);
		comboBoxPurchaseLocation.setVisible(initialyVisibleFalse);
		textPurchaseLocation.setVisible(initialyVisibleTrue);
		textGauge.setEditable(initialyVisibleFalse);
		textLength.setEditable(initialyVisibleFalse);
		textDateAddedToHumidor.setEditable(initialyVisibleFalse);
		textDescription.setEditable(initialyVisibleFalse);
		textPrice.setEditable(initialyVisibleFalse);
		textDateSmoked.setEditable(initialyVisibleFalse);
		textComment.setEditable(initialyVisibleFalse);
		ratingSlider.setEnabled(initialyVisibleFalse);
//		rdbtnFullySmoked.setEnabled(initialyVisibleFalse);
		comboBoxFinished.setVisible(initialyVisibleFalse);
		textFullySmoked.setVisible(initialyVisibleTrue);
		textMinutesSmoked.setEditable(initialyVisibleFalse);
		
		
		
		btnCancel.setVisible(initialyVisibleFalse);
		btnSave.setVisible(initialyVisibleFalse);
	}
}
